
<template>
  <div class="page_login">
    <div class="mask">
      <img src="../assets/imgs/login_center_bg.png" class="mask_img" />
    </div>

    <div class="login-box">
      <div style="margin-left:132px">
        <img src="../assets/imgs/login.png" alt />
      </div>
      <h2>mall-admin-web</h2>

      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" class="demo-ruleForm">
        <el-form-item prop="text" style="position:relative">
          <el-input
            type="text"
            v-model="ruleForm.text"
            autocomplete="off"
            prefix-icon="el-icon-user-solid"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>

        <el-form-item prop="pass">
          <el-input
            type="password"
            v-model="ruleForm.pass"
            autocomplete="off"
            prefix-icon="el-icon-lock"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" style="width:120px" @click="submitForm('ruleForm')">登录</el-button>
          <el-button type="primary" style="width:120px">获取体验账号</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入用户名"));
      } else {
        callback();
      }
    };

    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        callback();
      }
    };

    return {
      ruleForm: {
        pass: "",
        text: "admin",
      },
      rules: {
        pass: [{ validator: validatePass2, trigger: "blur" }],
        text: [{ validator: validatePass, trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        //设置登录密码
        let _this = this;
        if (valid && _this.ruleForm.pass == "123456") {
          //   let t = async function() {
          //     const { data: res } = await _this.$axios.post("/login", {
          //       username: _this.ruleForm.text,
          //       password: _this.ruleForm.pass
          //     });
          //   };
          window.sessionStorage.setItem("token", _this.ruleForm.text);
          location.href="/"
        } else {
          alert("密码错误");
          return false;
        }
      });
    },
  },
};
</script>
<style  scoped>
@import "../assets/index.css";
.page_login {
  height: 100vh;
  width: 100vw;
  position: relative;
  overflow-x: hidden;
}
.mask {
  position: absolute;
}
.mask_img {
  background: #409eff;
  width: auto; 
  /* height: auto; */
  width: 100%;
  /* max-height: 100%;  */
  margin-top: 200px;
}
.login-box {
  padding: 20px;
  background: #fff;
  position: absolute;
  left: 0;
  right: 0;
  width: 360px;
  margin: 110px auto;
  border-top: 10px solid #409eff;
}
h2 {
  text-align: center;
  color: #409eff;
  margin: 20px 0;
}
</style>